﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using dhDataAcess.dataAcess;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess.purchaseTableAdapters;
using baseSet.power;

namespace dhsystem.produceForm.pdrk
{
    public partial class FrmpdckMaster : Form
    {
        pdckBLL pdck = new pdckBLL();
        string state;
        public FrmpdckMaster()
        {
            InitializeComponent();
        }

        private void FrmpdckMaster_Load(object sender, EventArgs e)
        {
            getData();
        }

        private void buttupdate_Click(object sender, EventArgs e)
        {
            getData();
        }

        private void buttImport_Click(object sender, EventArgs e)
        {

        }

        private void toolAdd_Click(object sender, EventArgs e)
        {
            state = "新增";
            FrmpdckMasterAdd pdckMasterAdd = new FrmpdckMasterAdd(bindingSourcepdrkMaster, state);
            pdckMasterAdd.ShowDialog();
        }

        private void toolEdit_Click(object sender, EventArgs e)
        {
            state = "编辑";
            FrmpdckMasterAdd pdckMasterAdd = new FrmpdckMasterAdd(bindingSourcepdrkMaster, state);
            pdckMasterAdd.ShowDialog();
        }

        private void toolDel_Click(object sender, EventArgs e)
        {
            string billNo = dGridpdrkMaster.Rows[dGridpdrkMaster.CurrentRow.Index].Cells[1].Value.ToString();
            string billStatus = dGridpdrkMaster.CurrentRow.Cells["billStatus"].Value.ToString();
            if (billStatus == "结算")
            {
                MessageBox.Show("此订单已经结算，不能删除。如需删除请反结算");
                return;
            }
            try
            {
                DialogResult result = MessageBox.Show("是否删除：" + billNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    bindingSourcepdrkMaster.DataSource = pdck.pdckMasterDelII(billNo);

                }
                getData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void toolSave_Click(object sender, EventArgs e)
        {

        }

        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.pdrkMaster);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridpdrkDetail.DataSource = query.rTable;
            }
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.pdckMaster, dGridpdrkMaster, "胚带出库信息");
            frm.ShowDialog();
        }

        private void toolPrint_Click(object sender, EventArgs e)
        {

        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {

        }
        private void getData()
        {
            pdckDetailTableAdapter pdckDetailAdapter = new pdckDetailTableAdapter();
            pdckMasterTableAdapter pdckMasterAdapter = new pdckMasterTableAdapter();
            purchase pdck = new purchase();
            pdckDetailAdapter.FillpdckDetailAll(pdck.pdckDetail);
            pdckMasterAdapter.FillpdckMasterAll (pdck.pdckMaster);
            bindingSourcepdrkMaster.DataSource = pdck;
            bindingSourcepdrkMaster.DataMember = "pdckMaster";
            dGridpdrkMaster.DataSource = bindingSourcepdrkMaster;

            DcolumnSet.colSet(moduleInfo.pdckMaster, dGridpdrkMaster);
            toolStripStatusLabel1.Text = "胚带出库主表数据总条数:" + dGridpdrkMaster.RowCount.ToString() + "条";
            bindingSourcepdrkDetail.DataSource = bindingSourcepdrkMaster;

            bindingSourcepdrkDetail.DataMember = "fk_pdckDetail_billNo";
            dGridpdrkDetail.DataSource = bindingSourcepdrkDetail;
            DcolumnSet.colSet(moduleInfo.pdckDetail, dGridpdrkDetail);
            toolStripStatusLabel3.Text = "胚带出库从表数据总条数:" + dGridpdrkDetail.RowCount.ToString() + "条";

            sysDataSet.modulAaccessDataTable modulAaccess = powerSet.modulPower(moduleInfo.pdckMaster );
            foreach (sysDataSet.modulAaccessRow modulAaccessRow in modulAaccess)
            {
                buttonQuery.Enabled = modulAaccessRow.showAc;
                toolAdd.Enabled = modulAaccessRow.addAc;
                toolEdit.Enabled = modulAaccessRow.editAc;
                toolDel.Enabled = modulAaccessRow.delAc;
                toolPrint.Enabled = modulAaccessRow.printAc;
                toolExport.Enabled = modulAaccessRow.exportAc;
                //buttImport.Enabled = modulAaccessRow.importAc;

            }
        }
    }
}
